package jmu.edu.yjc;

import jmu.edu.yjc.server.WebSocketServer;
import jmu.edu.yjc.service.MessageService;
import jmu.edu.yjc.service.UnAnsweredQuestionService;
import jmu.edu.yjc.service.answer.AnswerService;
import jmu.edu.yjc.service.user.UserService;
import org.mybatis.spring.annotation.MapperScan;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.ConfigurableApplicationContext;
import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.scheduling.annotation.EnableScheduling;

@SpringBootApplication
@EnableScheduling
@MapperScan("jmu.edu.yjc.mapper")
public class CSAMSAdminApplication {
    public static void main(String[] args) {
        ConfigurableApplicationContext applicationContext = SpringApplication.run(CSAMSAdminApplication.class, args);
        initWebSocketClass(applicationContext);
    }
    private static void initWebSocketClass(ConfigurableApplicationContext applicationContext){
        WebSocketServer.setApplicationContext(applicationContext);
        WebSocketServer.setStringRedisTemplate(applicationContext.getBean(StringRedisTemplate.class));
        WebSocketServer.setUserService(applicationContext.getBean(UserService.class));
        WebSocketServer.setMessageService(applicationContext.getBean(MessageService.class));
        WebSocketServer.setAnswerService(applicationContext.getBean(AnswerService.class));
        WebSocketServer.setUnAnsweredQuestionService(applicationContext.getBean(UnAnsweredQuestionService.class));
    }
}
